import Vue from 'vue'
import VueRouter from 'vue-router'
import LoginPage from '@/components/LoginPage'
import UserPage from '@/components/UserPage'

import home from '@/components/UserPageHome'
import UserInfo from '@/components/UserInfo'
import UserQueryBill from '@/components/UserQueryBill'
import UpdateUserInfo from '@/components/UpdateUserInfo'
import UserChangePassword from '@/components/UserChangePassword'
import UserChangeEmail from '@/components/UserChangeEmail'
import UserChangePlate from '@/components/UserChangePlate'
import UserBillRecharge from '@/components/UserBillRecharge'
import UserBillRefund from '@/components/UserBillRefund' 
import UserPlateRecharge from '@/components/UserPlateRecharge'
import UserPlateRefund from '@/components/UserPlateRefund'
import UserPlateBill from '@/components/UserPlateBill'

import AdminPage from '@/components/AdminPage'
import AdminQueryInfo from '@/components/AdminQueryInfo'
import AdminChangeInfo from '@/components/AdminChangeInfo'
import AdminChangeEmail from '@/components/AdminChangeEmail'
import AdminChangePlate from '@/components/AdminChangePlate'
import AdminbillRecharge from '@/components/AdminbillRecharge'
import AdminBillRefund from '@/components/AdminBillRefund'
import AdminPlateRecharge from '@/components/AdminPlateRecharge'
import AdminPlateRefund from '@/components/AdminPlateRefund'

const routes = [
  // 路由重定向
  {path : '/',redirect :'/LoginPage'},
  {path : '/LoginPage',component : LoginPage},
  {
    path : '/UserPage',component : UserPage,
    children:[
      {path : '/UserPage',redirect:'/UserPage/home'},
      {path : '/UserPage/home',component : home},
      {path : '/UserPage/queryInfo',component : UserInfo},
      {path : '/UserPage/queryBill',component : UserQueryBill},
      {path : '/UserPage/changeUserInfo',component : UpdateUserInfo},
      {path : '/UserPage/changePassword',component : UserChangePassword},
      {path : '/UserPage/changeEmail',component : UserChangeEmail},
      {path : '/UserPage/changePlate',component : UserChangePlate},
      {path : '/UserPage/billRecharge',component : UserBillRecharge},
      {path : '/UserPage/billRefund',component : UserBillRefund},
      {path : '/UserPage/plateRecharge',component : UserPlateRecharge},
      {path : '/UserPage/plateRefund',component : UserPlateRefund},
      {path : '/UserPage/plateBill',component : UserPlateBill},
    ]
  },
  {path : '/AdminPage',component : AdminPage,
    children:[
      {path:'/AdminPage',redirect:'/AdminPage/queryInfo'},
      {path:'/AdminPage/queryInfo',component : AdminQueryInfo},
      {path:'/AdminPage/queryBill',component : UserQueryBill},
      {path:'/AdminPage/changeUserInfo',component : AdminChangeInfo},
      {path:'/AdminPage/changeEmail',component : AdminChangeEmail},
      {path:'/AdminPage/changePlate',component : AdminChangePlate},
      {path:'/AdminPage/billRecharge',component : AdminbillRecharge},
      {path:'/AdminPage/billRefund',component : AdminBillRefund},
      {path:'/AdminPage/plateRecharge',component : AdminPlateRecharge},
      {path:'/AdminPage/plateRefund',component : AdminPlateRefund},
    ]
  },
]

Vue.use(VueRouter)

const router = new VueRouter({
  routes : routes
})

router.beforeEach((to,from,next)=>{
  if(to.path==='/UserPage'||to.path==='/AdminPage'){
    if(window.sessionStorage.getItem('token') === null){
      next('/LoginPage') 
    }
  }
  next()
})

export default router
